1 =============================================================================
2 CONSOLE APPLICATION : CppVhdAPI Project Overview
3 =============================================================================
5 /////////////////////////////////////////////////////////////////////////////
8 The code sample demonstrates various VHD API usage, such as VHD creation,
9 attaching, detaching and getting and setting disk information.
12 /////////////////////////////////////////////////////////////////////////////
15 The code sample must be run on Windows 7 / Windows Server 2008 R2 or newer.
16 The minimum supported client of the VHD APIs is Windows 7; and the minimum
17 supported server of the VHD APIs is Windows Server 2008 R2.
20 /////////////////////////////////////////////////////////////////////////////
23 CppVhdAPI.exe -[cxaomdgpe] -f <vhdfile> -s <size>
24 -c CreateVirtualDisk............input: -f <vhd file name>, -s <size in MB>
25 -a AttachVirtualDisk............input: -f <vhd file name>
26 -d DetachVirtualDisk............input: -f <vhd file name>
27 -g GetVirtualDiskInformation....input: -f <vhd file name>
28 -p GetVirtualDiskPhysicalPath...input: -f <vhd file name> -- note: must be attached
29 -e SetVirtualDiskInformation....input: -f <vhd file name>, -u <new GUID>
32 Create a 3.6 Gb VHD named 'mytest.vhd'
33 CppVhdAPI.exe -c -f c:\testdir\mytest.vhd -s 3600
35 Attach a VHD named 'mytest.vhd'
36 CppVhdAPI.exe -a -f c:\testdir\mytest.vhd
37 After the virtual disk is attached, you can find the disk in Disk
38 Management MMC (Microsoft Management Console). You can initialize the
39 disk and partition it.
41 Set VHD GUID 'mytest.vhd'
42 CppVhdAPI.exe -e -f c:\testdir\mytest.vhd -u {12345678-1234-5678-1234-000000000000}
44 Detach a VHD named 'mytest.vhd'
45 CppVhdAPI.exe -d -f c:\testdir\mytest.vhd
46 After the virtual disk is detached, the disk will disappear in Disk
47 Management MMC (Microsoft Management Console).
50 /////////////////////////////////////////////////////////////////////////////
53 The main logic of this code is:
55 1. parse and validate input parameters
56 2. execute command and parameters resulting in the action to the VHD. In
57 this code sample, the usage of the following APIs are demoed.
60 - Creates a virtual hard disk (VHD) image file
63 - Opens a virtual hard disk (VHD) for use
66 - Attaches a virtual hard disk (VHD) by locating an appropriate VHD
67 provider to accomplish the attachment.
70 - Detaches a virtual hard disk (VHD) by locating an appropriate VHD
71 provider to accomplish the operation.
73 GetVirtualDiskInformation
74 - Retrieves information about a virtual hard disk (VHD).
76 GetVirtualDiskPhysicalPath
77 - Retrieves the path to the physical device object that contains a
78 virtual hard disk (VHD).
80 SetVirtualDiskInformation
81 - Sets information about a virtual hard disk (VHD).
84 /////////////////////////////////////////////////////////////////////////////
87 The location for complete information on VHDs is:
88 http://msdn.microsoft.com/en-us/library/dd323684(v=VS.85).aspx
90 The Virtual Disk API In Windows 7
91 http://msdn.microsoft.com/en-us/magazine/dd569754.aspx
94 /////////////////////////////////////////////////////////////////////////////